﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Controls;

namespace StudentManagement.Util.ValidationRules
{
    public class MinLengthValidation : ValidationRule
    {
        private readonly int _minLength;
        private readonly string _errorMsg;

        /// <summary>
        /// 校验最小长度
        /// </summary>
        /// <param name="maxLength">最小长度</param>
        /// <param name="ErrorMsg">错误消息</param>
        public MinLengthValidation(int minLength, string ErrorMsg)
        {
            _minLength = minLength;
            _errorMsg = ErrorMsg;
        }


        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (value != null && value != (object)string.Empty)
            {
                if (value.ToString().Length < _minLength)
                {
                    return new ValidationResult(false, _errorMsg);
                }
            }
            return ValidationResult.ValidResult;
        }
    }
}
